<link rel="stylesheet" type="text/css" href="css/fitem.css">
<script type="text/javascript">

    var url;
    var urlstep2;
    var newtemp;
    var edittemp;
    var removetemp;
    var canceltemp;
            
    function newpo_in(){
        $('#dlgPo_In').dialog('open').dialog('setTitle','New Po_In');
        $('#fmPo_In').form('clear');
            url = 'pages/po_in/po_in_new.php';
        $('#combo_namaCustomer').combobox({
            url:"pages/combodata.php?field=customer"
        });
        $('#discount_po_in').val('100');
    }
            
    function editpo_in(){
        var row = $('#dgPo_In').datagrid('getSelected');
        if (row){
            $('#fmPo_In').form('clear');
            $('#combo_namaCustomer').combobox({
                url:"pages/combodata.php?field=customer"
            });
            $('#dlgPo_In').dialog('open').dialog('setTitle','Edit Po_In');
            $('#fmPo_In').form('load',row);
        }else{
            $.messager.alert('Warning','Pilih dulu salah satu Po_In.','warning');
        }
    }
            
    function savepo_in(){
        $('#fmPo_In').form('submit',{
            url: url,
            onSubmit: function(){
                return $(this).form('validate');
            },
            success: function(result){
                var result = eval('('+result+')');
                if (result.success){
                    $('#dlgPo_In').dialog('close');		// close the dialog
                    $('#dgPo_In').datagrid('reload');	// reload the user data
                    $.messager.show({
                        title: 'Sukses',
                        msg: result.msg
                    });
                } else {
                    $.messager.show({
                        title: 'Error',
                        msg: result.msg
                    });
                }
            }
        });
    }
    function removepo_in(){
        var row = $('#dgPo_In').datagrid('getSelected');
        if (row){
            $.messager.confirm('Confirm','Are you sure you want to remove this po_in?',function(r){
                if (r){
                    $.post('pages/po_in/po_in_remove.php',{id:row.id},function(result){
                        if (result.success){
                            $('#dgPo_In').datagrid('reload');	// reload the user data
                        } else {
                            $.messager.show({	// show error message
                                title: 'Error',
                                msg: result.msg
                            });
                        }
                    },'json');
                }
            });
        }
    }
    $(function(){
        $('#poinfilternamacustomer').combogrid({
            panelWidth:300,
            idField:'idCustomer',
            textField:'namaCustomer',
            url:'pages/getCombogridData.php?field=customer',
            mode:'remote',
            fitColumns:true,
            columns:[[
                    {field:'idCustomer',title:'ID Customer',width:60},
                    {field:'namaCustomer',title:'Nama Customer',width:60}
                ]]
        });
    });
    
    function doSearchDataPoIn(){
        var postThis = $('#fcariPOIN').serialize();
        $('#dgPo_In').datagrid('reload',{
            ref:postThis
        });
    }
    
    function getDetailJob(idjob){
        $('#dlgDetailJob').dialog('open');
        $('#frDetailJob').attr({src:"pages/po_in/po_in_getdetail.php?id="+idjob});
    }
            
</script>

<!--    table halaman utama daftar po_in-->
<table id="dgPo_In" title="Daftar Po_In" class="easyui-datagrid"
       url="pages/po_in/po_in_getdata.php"
       toolbar="#toolbarPo_In" pagination="true"
       rownumbers="true" fitColumns="true" singleSelect="true">
    <thead>
        <tr>
            <th field="inputdate_job" width="50">Date</th>
            <th field="no_job" width="50">Job No.</th>
            <th field="no_po_in" width="50">PO/SPK No</th>
            <th field="idCustomer" width="50" hidden="true">ID Customer</th>
            <th field="namaCustomer" width="50">Customer</th>
            <th field="desc_job" width="200">Description</th>
            <th field="dpp_job" width="50" align="right">DPP</th>
            <th field="inputby_job" width="50">Sales</th>
            <th field="status_job" width="50">Status</th>
            <th field="discount_job" width="50">Discount</th>
            <th field="detail" width="50">Detail</th>
        </tr>
    </thead>
</table>
<div id="toolbarPo_In" style="padding: 10px; height: auto">
    <form id="fcariPOIN">
        Job No: 
        <input class='easyui-validatebox' type='text' name='filterjobno' id='poinfilterjobno'>
        PO/SPK No: 
        <input class='easyui-validatebox' type='text' name='filterpospkno' id='poinfilterpospkno'>
        Customer: 
        <input class='easyui-validatebox' type='text' name='filternamacustomer' id='poinfilternamacustomer'>
        Job Status: 
        <select class='easyui-combobox' name='filterjobjtatus' id='poinfilterjobstatus' panelheight="80px" panelwidth="90px" style="width:90px">
            <option value="H">Hold</option>
            <option value="D">Done</option>
            <option value="P">Pending</option>
            <option value="" selected="selected">All</option>
        </select>
        <a href='javascript:void(0)' class='easyui-linkbutton' iconCls='icon-search' onclick='doSearchDataPoIn()'>Cari Data</a>
    </form>
    <br>
    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" onclick="newpo_in()">New</a>
    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-edit" onclick="editpo_in()">Edit</a>
    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-remove" onclick="removepo_in()">Remove</a>
</div>

<!--dialog membuat po_in baru-->
<div id="dlgPo_In" class="easyui-dialog" style="width:550px;height:auto;padding:10px;" 
     buttons="#dlgPo_In_step1-button" closed="true" modal="true" closable="false">
    <form id="fmPo_In" method="post" class="fitem">
        <table>
            <tr>
                <td width="70">No. Job</td>
                <td><input id="no_job" name="no_job" class="easyui-validatebox" type="text" placeholder="%000000000001" readonly></td>
            </tr>
            <tr>
                <td>No. PO_In</td>
                <td><input type="text" name="no_po_in" id="no_po_in"  class="easyui-validatebox" required></td>
            </tr>
            <tr>
                <td>Customer</td><td><input id="combo_namaCustomer" 
                   class='easyui-combobox' name="idCustomer" valueField="idCustomer" 
                   textField="namaCustomer" panelHeight="150px" style="width:200px;"></td>
            </tr>
            <tr>
                <td>Desc</td><td><textarea id="desc_po_in" name="desc_po_in" 
                   class="easyui-validatebox" style="height:50px;width:420px" required></textarea></td>
            </tr>
            <tr>
                <td>DPP</td><td><input type="text" name="dpp_po_in" id="dpp_po_in" class="easyui-validatebox" required></td>
            </tr>
            <tr>
                <td>Discount</td><td><input type="text" name="discount_po_in" id="discount_po_in" class="easyui-validatebox" style="width:40px" required>%</td>
            </tr>
        </table>
    </form>
    <div id="dlgPo_In_step1-button">
        <a href="javascript:void(0)" class="easyui-linkbutton" onclick="savepo_in()" iconCls="icon-ok" plain="true">Save</a>            
        <a href="javascript:void(0)" class="easyui-linkbutton" onclick="javascript:$('#dlgPo_In').dialog('close')" iconCls="icon-cancel" plain="true">Cancel</a>            
    </div>
</div>

<!--dialog detail job-->
<div id="dlgDetailJob" class="easyui-dialog" style="width:550px;height:600px;padding:10px;" 
     closed="true" modal="true" title="Detail Job">
    <iframe id="frDetailJob" frameborder="0" scrolling="auto" style="height: 100%;width: 100%"></iframe>
</div>
